script_enemy_main{

let effect1=0;
let object1=[];
let timer1=[];
let scale1=[];
let bounce1=[];

let character="Amaya";
let cutin=character;
let dispelled=0;
let spellcards=2;
if(GetCommonData("Difficulty")==4){ spellcards=3; }
let damagerate=10;
let outfit=1;
outfit=(128*outfit)-128;
let usespell=0;
let frame=0; let time=0;
let miny=GetClipMinY; let maxy=GetClipMaxY; let minx=GetClipMinX; let maxx=GetClipMaxX;
let cx=GetCenterX; let cy=GetCenterY;

let EFmoon=("\script\Shots\Biggest.png");
let SEspawn1=("\script\SoundEffects\spawn1.wav");
let SEshotm3=("\script\SoundEffects\shotm3.wav");

let GRboss=("\script\Images\CharacterSprites\Amaya.png");

#include_function "script/Functions/HealthBarLoad.txt";

@Initialize{
	LoadUserShotData("script\shots\ShotsAmaya1.txt");
	LoadGraphic(GRboss);

	LoadGraphic("\script\Shots\Biggest.png");
	LoadSE("\script\SoundEffects\spawn1.wav");
	LoadSE("\script\SoundEffects\shotm3.wav");

	SetLife(150);
	SetTimer(30);
	SetInvincibility(120);
	SetDamageRate(10,10); 
	SetEnemyMarker(true);
	MagicCircle(true);
	SetMovePosition02(cx,miny+100,50);
}
	
@MainLoop{

SetCollisionA(GetX,GetY,16);
SetCollisionB(GetX,GetY,16);
SetShotAutoDeleteClip(64,64,64,64);

Weakness(character);
#include_function "script/Functions/Weakness.txt";
if(GetCommonData("BombOn")==0){ damagerate=10; }
if(GetCommonData("BombOn")==1){ damagerate=4; }
SetDamageRate(damagerate*weaken,damagerate*weaken);

HealthBar();

if(time%200==0 && time>=60){
	if(GetPlayerX>minx+50 && GetPlayerX<maxx-50){
	SetMovePosition01(GetPlayerX+rand(-30,30),rand(miny+60,miny+120),1.5);
	}
	if(GetPlayerX<=minx+50){
	SetMovePosition01(GetPlayerX+rand(15,30),rand(miny+60,miny+120),1.5);
	}
	if(GetPlayerX>=maxx-50){
	SetMovePosition01(GetPlayerX-rand(15,30),rand(miny+60,miny+120),1.5);
	}
}



if(GetCommonData("Difficulty")==1){

if((time+90)%150==0 && time>=60){
let angle=0;
if((time+90)%300==0){ angle=0; }
if((time+90)%300!=0){ angle=360/8; }
	angle+=360/4;
	loop(2){
		loop(2){
		let id=0;
			loop(2){
			effect1=(Obj_Create(OBJ_EFFECT));
			Obj_SetPosition(effect1,GetX,GetY);
			ObjEffect_SetScale(effect1,0,0);
			Obj_SetSpeed(effect1,0); Obj_SetAngle(effect1,angle);
			ObjEffect_SetLayer(effect1,3); ObjEffect_SetTexture(effect1,EFmoon); ObjEffect_SetRenderState(effect1,ALPHA);
			ObjEffect_SetPrimitiveType(effect1,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(effect1,4);
			ObjEffect_SetVertexXY(effect1,0,-80,-80); ObjEffect_SetVertexUV(effect1,0,160,0);
			ObjEffect_SetVertexXY(effect1,1,80,-80); ObjEffect_SetVertexUV(effect1,1,319,0);
			ObjEffect_SetVertexXY(effect1,2,-80,80); ObjEffect_SetVertexUV(effect1,2,160,159);
			ObjEffect_SetVertexXY(effect1,3,80,80); ObjEffect_SetVertexUV(effect1,3,319,159);
			ObjEffect_SetVertexColor(effect1,0,255,255,255,230); ObjEffect_SetVertexColor(effect1,1,255,255,255,230);
			ObjEffect_SetVertexColor(effect1,2,255,255,255,230); ObjEffect_SetVertexColor(effect1,3,255,255,255,230);
			object1=object1~[effect1];
			timer1=timer1~[effect1];
			timer1[length(object1)-1]=0;
			scale1=scale1~[effect1];
			scale1[length(object1)-1]=0;
			bounce1=bounce1~[effect1];
			bounce1[length(object1)-1]=id;
			id++;
			}
		angle+=360/2;
		}
	angle+=360/4;
	}
PlaySE(SEspawn1);
usespell=-30;
}

let i=0;
while(i<length(object1)){
	if(Obj_BeDeleted(object1[i])){
	object1=erase(object1,i); timer1=erase(timer1,i); scale1=erase(scale1,i); bounce1=erase(bounce1,i);
	i--;
	}
	else{
	Obj_SetPosition(object1[i],Obj_GetX(object1[i])+Obj_GetSpeed(object1[i])*cos(Obj_GetAngle(object1[i])),Obj_GetY(object1[i])+Obj_GetSpeed(object1[i])*sin(Obj_GetAngle(object1[i])));
	ObjEffect_SetScale(object1[i],scale1[i],scale1[i]);
	ObjEffect_SetAngle(object1[i],0,0,timer1[i]*2);
	SetCollisionB(Obj_GetX(object1[i]),Obj_GetY(object1[i]),55*scale1[i]);

	if(scale1[i]<1){ scale1[i]=scale1[i]+0.1; }
	if(scale1[i]>=1){ Obj_SetSpeed(object1[i],1); }

	if((Obj_GetX(object1[i])<=minx || Obj_GetX(object1[i])>=maxx || Obj_GetY(object1[i])<=miny || Obj_GetY(object1[i])>=maxy) && bounce1[i]==0){
	bounce1[i]=1;
	let angle2=rand(0,360);
		loop(7){
		CreateShot02(Obj_GetX(object1[i]),Obj_GetY(object1[i]),2,angle2,-0.08,0.9,165,10);
		angle2+=360/14;
		CreateShot02(Obj_GetX(object1[i]),Obj_GetY(object1[i]),2,angle2,-0.08,1.2,153,10);
		angle2+=360/14;
		}
	PlaySE(SEshotm3);
	}

	timer1[i]=timer1[i]+1;
	}
i++;
}

} // Easy

//=============================================================================================================

if(GetCommonData("Difficulty")==2){

if((time+90)%150==0 && time>=60){
let angle=0;
if((time+90)%300==0){ angle=0; }
if((time+90)%300!=0){ angle=360/12; }
	angle+=360/6;
	loop(2){
		loop(3){
		let id=0;
			loop(2){
			effect1=(Obj_Create(OBJ_EFFECT));
			Obj_SetPosition(effect1,GetX,GetY);
			ObjEffect_SetScale(effect1,0,0);
			Obj_SetSpeed(effect1,0); Obj_SetAngle(effect1,angle);
			ObjEffect_SetLayer(effect1,3); ObjEffect_SetTexture(effect1,EFmoon); ObjEffect_SetRenderState(effect1,ALPHA);
			ObjEffect_SetPrimitiveType(effect1,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(effect1,4);
			ObjEffect_SetVertexXY(effect1,0,-80,-80); ObjEffect_SetVertexUV(effect1,0,160,0);
			ObjEffect_SetVertexXY(effect1,1,80,-80); ObjEffect_SetVertexUV(effect1,1,319,0);
			ObjEffect_SetVertexXY(effect1,2,-80,80); ObjEffect_SetVertexUV(effect1,2,160,159);
			ObjEffect_SetVertexXY(effect1,3,80,80); ObjEffect_SetVertexUV(effect1,3,319,159);
			ObjEffect_SetVertexColor(effect1,0,255,255,255,230); ObjEffect_SetVertexColor(effect1,1,255,255,255,230);
			ObjEffect_SetVertexColor(effect1,2,255,255,255,230); ObjEffect_SetVertexColor(effect1,3,255,255,255,230);
			object1=object1~[effect1];
			timer1=timer1~[effect1];
			timer1[length(object1)-1]=0;
			scale1=scale1~[effect1];
			scale1[length(object1)-1]=0;
			bounce1=bounce1~[effect1];
			bounce1[length(object1)-1]=id;
			id++;
			}
		angle+=360/3;
		}
	angle+=360/6;
	}
PlaySE(SEspawn1);
usespell=-30;
}

let i=0;
while(i<length(object1)){
	if(Obj_BeDeleted(object1[i])){
	object1=erase(object1,i); timer1=erase(timer1,i); scale1=erase(scale1,i); bounce1=erase(bounce1,i);
	i--;
	}
	else{
	Obj_SetPosition(object1[i],Obj_GetX(object1[i])+Obj_GetSpeed(object1[i])*cos(Obj_GetAngle(object1[i])),Obj_GetY(object1[i])+Obj_GetSpeed(object1[i])*sin(Obj_GetAngle(object1[i])));
	ObjEffect_SetScale(object1[i],scale1[i],scale1[i]);
	ObjEffect_SetAngle(object1[i],0,0,timer1[i]*2);
	SetCollisionB(Obj_GetX(object1[i]),Obj_GetY(object1[i]),55*scale1[i]);

	if(scale1[i]<1){ scale1[i]=scale1[i]+0.1; }
	if(scale1[i]>=1){ Obj_SetSpeed(object1[i],1); }

	if((Obj_GetX(object1[i])<=minx || Obj_GetX(object1[i])>=maxx || Obj_GetY(object1[i])<=miny || Obj_GetY(object1[i])>=maxy) && bounce1[i]==0){
	bounce1[i]=1;
	let angle2=rand(0,360);
		loop(9){
		CreateShot02(Obj_GetX(object1[i]),Obj_GetY(object1[i]),2,angle2,-0.08,0.9,165,10);
		angle2+=360/18;
		CreateShot02(Obj_GetX(object1[i]),Obj_GetY(object1[i]),2,angle2,-0.08,1.2,153,10);
		angle2+=360/18;
		}
	PlaySE(SEshotm3);
	}

	timer1[i]=timer1[i]+1;
	}
i++;
}

} // Normal

//=============================================================================================================

if(GetCommonData("Difficulty")==3){

if((time+90)%150==0 && time>=60){
let angle=0;
if((time+90)%300==0){ angle=0; }
if((time+90)%300!=0){ angle=360/16; }
	angle+=360/8;
	loop(2){
		loop(4){
		let id=0;
			loop(2){
			effect1=(Obj_Create(OBJ_EFFECT));
			Obj_SetPosition(effect1,GetX,GetY);
			ObjEffect_SetScale(effect1,0,0);
			Obj_SetSpeed(effect1,0); Obj_SetAngle(effect1,angle);
			ObjEffect_SetLayer(effect1,3); ObjEffect_SetTexture(effect1,EFmoon); ObjEffect_SetRenderState(effect1,ALPHA);
			ObjEffect_SetPrimitiveType(effect1,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(effect1,4);
			ObjEffect_SetVertexXY(effect1,0,-80,-80); ObjEffect_SetVertexUV(effect1,0,160,0);
			ObjEffect_SetVertexXY(effect1,1,80,-80); ObjEffect_SetVertexUV(effect1,1,319,0);
			ObjEffect_SetVertexXY(effect1,2,-80,80); ObjEffect_SetVertexUV(effect1,2,160,159);
			ObjEffect_SetVertexXY(effect1,3,80,80); ObjEffect_SetVertexUV(effect1,3,319,159);
			ObjEffect_SetVertexColor(effect1,0,255,255,255,230); ObjEffect_SetVertexColor(effect1,1,255,255,255,230);
			ObjEffect_SetVertexColor(effect1,2,255,255,255,230); ObjEffect_SetVertexColor(effect1,3,255,255,255,230);
			object1=object1~[effect1];
			timer1=timer1~[effect1];
			timer1[length(object1)-1]=0;
			scale1=scale1~[effect1];
			scale1[length(object1)-1]=0;
			bounce1=bounce1~[effect1];
			bounce1[length(object1)-1]=id;
			id++;
			}
		angle+=360/4;
		}
	angle+=360/8;
	}
PlaySE(SEspawn1);
usespell=-30;
}

let i=0;
while(i<length(object1)){
	if(Obj_BeDeleted(object1[i])){
	object1=erase(object1,i); timer1=erase(timer1,i); scale1=erase(scale1,i); bounce1=erase(bounce1,i);
	i--;
	}
	else{
	Obj_SetPosition(object1[i],Obj_GetX(object1[i])+Obj_GetSpeed(object1[i])*cos(Obj_GetAngle(object1[i])),Obj_GetY(object1[i])+Obj_GetSpeed(object1[i])*sin(Obj_GetAngle(object1[i])));
	ObjEffect_SetScale(object1[i],scale1[i],scale1[i]);
	ObjEffect_SetAngle(object1[i],0,0,timer1[i]*2);
	SetCollisionB(Obj_GetX(object1[i]),Obj_GetY(object1[i]),55*scale1[i]);

	if(scale1[i]<1){ scale1[i]=scale1[i]+0.1; }
	if(scale1[i]>=1){ Obj_SetSpeed(object1[i],1); }

	if((Obj_GetX(object1[i])<=minx || Obj_GetX(object1[i])>=maxx || Obj_GetY(object1[i])<=miny || Obj_GetY(object1[i])>=maxy) && bounce1[i]==0){
	bounce1[i]=1;
	let angle2=rand(0,360);
		loop(10){
		CreateShot02(Obj_GetX(object1[i]),Obj_GetY(object1[i]),3,angle2,-0.08,1.2,165,10);
		CreateShot02(Obj_GetX(object1[i]),Obj_GetY(object1[i]),3,angle2,-0.08,1.5,153,10);
		angle2+=360/10;
		}
	PlaySE(SEshotm3);
	}

	timer1[i]=timer1[i]+1;
	}
i++;
}

} // Hard

//=============================================================================================================

if(GetCommonData("Difficulty")==4){

if((time+90)%150==0 && time>=60){
let angle=0;
if((time+90)%300==0){ angle=0; }
if((time+90)%300!=0){ angle=360/20; }
	angle+=360/10;
	loop(2){
		loop(5){
		let id=0;
			loop(2){
			effect1=(Obj_Create(OBJ_EFFECT));
			Obj_SetPosition(effect1,GetX,GetY);
			ObjEffect_SetScale(effect1,0,0);
			Obj_SetSpeed(effect1,0); Obj_SetAngle(effect1,angle);
			ObjEffect_SetLayer(effect1,3); ObjEffect_SetTexture(effect1,EFmoon); ObjEffect_SetRenderState(effect1,ALPHA);
			ObjEffect_SetPrimitiveType(effect1,PRIMITIVE_TRIANGLESTRIP); ObjEffect_CreateVertex(effect1,4);
			ObjEffect_SetVertexXY(effect1,0,-80,-80); ObjEffect_SetVertexUV(effect1,0,160,0);
			ObjEffect_SetVertexXY(effect1,1,80,-80); ObjEffect_SetVertexUV(effect1,1,319,0);
			ObjEffect_SetVertexXY(effect1,2,-80,80); ObjEffect_SetVertexUV(effect1,2,160,159);
			ObjEffect_SetVertexXY(effect1,3,80,80); ObjEffect_SetVertexUV(effect1,3,319,159);
			ObjEffect_SetVertexColor(effect1,0,255,255,255,230); ObjEffect_SetVertexColor(effect1,1,255,255,255,230);
			ObjEffect_SetVertexColor(effect1,2,255,255,255,230); ObjEffect_SetVertexColor(effect1,3,255,255,255,230);
			object1=object1~[effect1];
			timer1=timer1~[effect1];
			timer1[length(object1)-1]=0;
			scale1=scale1~[effect1];
			scale1[length(object1)-1]=0;
			bounce1=bounce1~[effect1];
			bounce1[length(object1)-1]=id;
			id++;
			}
		angle+=360/5;
		}
	angle+=360/10;
	}
PlaySE(SEspawn1);
usespell=-30;
}

let i=0;
while(i<length(object1)){
	if(Obj_BeDeleted(object1[i])){
	object1=erase(object1,i); timer1=erase(timer1,i); scale1=erase(scale1,i); bounce1=erase(bounce1,i);
	i--;
	}
	else{
	Obj_SetPosition(object1[i],Obj_GetX(object1[i])+Obj_GetSpeed(object1[i])*cos(Obj_GetAngle(object1[i])),Obj_GetY(object1[i])+Obj_GetSpeed(object1[i])*sin(Obj_GetAngle(object1[i])));
	ObjEffect_SetScale(object1[i],scale1[i],scale1[i]);
	ObjEffect_SetAngle(object1[i],0,0,timer1[i]*2);
	SetCollisionB(Obj_GetX(object1[i]),Obj_GetY(object1[i]),55*scale1[i]);

	if(scale1[i]<1){ scale1[i]=scale1[i]+0.1; }
	if(scale1[i]>=1){ Obj_SetSpeed(object1[i],1); }

	if((Obj_GetX(object1[i])<=minx || Obj_GetX(object1[i])>=maxx || Obj_GetY(object1[i])<=miny || Obj_GetY(object1[i])>=maxy) && bounce1[i]==0){
	bounce1[i]=1;
	let angle2=rand(0,360);
		loop(12){
		CreateShot02(Obj_GetX(object1[i]),Obj_GetY(object1[i]),3,angle2,-0.08,1.2,165,10);
		CreateShot02(Obj_GetX(object1[i]),Obj_GetY(object1[i]),3,angle2,-0.08,1.5,153,10);
		angle2+=360/12;
		}
	PlaySE(SEshotm3);
	}

	timer1[i]=timer1[i]+1;
	}
i++;
}

} // Lunatic


time++; frame++;
if(usespell>0){ usespell--; } if(usespell<0){ usespell++; }
SetCommonData("Boss1X",GetX); SetCommonData("Boss1Y",GetY);

#include_function "script/Functions/HealthBar.txt";

SetCommonData("Boss1X",GetX); SetCommonData("Boss1Y",GetY);
}

@DrawLoop{
	SetGraphicScale(1,1);
	SetTexture(GRboss);
	SetGraphicAngle(0,0,0);
	SetColor(255,255,255);
	SetRenderState(ALPHA);

	if(usespell>=1){ SetGraphicRect(384,outfit,512,outfit+128); }
	if(usespell<=-1){ SetGraphicRect(512,outfit,640,outfit+128); }

	if(usespell==0){
		if(GetSpeedX<=0.5 && GetSpeedX>=-0.5){ SetGraphicRect(0,outfit,128,outfit+128); }
		else if(GetSpeedX<-0.5){ SetGraphicRect(128,outfit,256,outfit+128); }
		else if(GetSpeedX>0.5){ SetGraphicRect(256,outfit,384,outfit+128); }
	}
	if(GetLife>0){ DrawGraphic(GetX,GetY); }
}
 
@Finalize{
}

}